﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ARD.Security.Cryptography;
using ARD.Security.Cryptography.Symmetric;

namespace SharpCommunications.Cryptography
{


    public class DefaultCryptographer : ISharpCryptographer
    {
        private ICryptoProvider cryptoProvider;
        private string keyFilePath;
        private KeyFile keyFile;
        private Cryptographer cryptographer;

        public DefaultCryptographer(string keyFilePath)
        {
            this.keyFilePath = keyFilePath;
            this.cryptoProvider = new RijndaelProvider();
            this.keyFile = new KeyFile(this.keyFilePath, this.cryptoProvider);
            this.keyFile.Load();
            this.cryptographer = new Cryptographer(this.cryptoProvider);
        }

        public string EncryptAndEncodeToBase64(string data)
        {
            string encrypted = this.cryptographer.EncryptToBase64Text(data);
            return encrypted;
        }

        public string DecodeFromBase64AndDecrypt(string encrypted)
        {
            string data = this.cryptographer.DecryptToUtf8Text(encrypted);
            return data;
        }
    }
}
